<template>
  <div>
    <hd-tab :tabs="tabs"/>
    <el-form ref="form" :inline="false" :model="form" label-width="80px" size="normal">
      <el-card :body-style="{ padding: '20px' }" shadow="never">
        <div slot="header">
          会员管理
        </div>
        <el-form-item label="名称">
          <el-input v-model="form.name" placeholder="简介说明"></el-input>
          <hd-error name="name"/>
        </el-form-item>

        <el-form-item label="手机号">
          <el-input v-model="form.mobile" placeholder="手机号"></el-input>
          <hd-error name="mobile"/>
        </el-form-item>
        <el-form-item label="用户头像">
          <hd-image v-model="form.avatar" :form="form" placeholder="用户头像"
          ></hd-image>
          <hd-error name="avatar"/>
        </el-form-item>
        <el-form-item label="邮箱">
          <el-input v-model="form.email" placeholder="邮箱"></el-input>
          <hd-error name="email"/>
        </el-form-item>
        <el-button type="primary" @click="onSubmit">提交</el-button>

      </el-card>
    </el-form>

  </div>
</template>

<script>
import tabs from './tabs'

const approve = {
  merchant_name: '', merchant_type: null,
  merchant_district: null, merchant_poster: [],
  merchant_introduce: null, merchant_education: null,
  merchant_phone: null, merchant_address: null,
  merchant_latitudeAndLongitude: [0, 0],
}
export default {
  route: false,
  props: ['id'],
  data() {
    return {
      tabs,
      form: {}
    }
  },
  async created() {
    if (this.id) {
      this.form = await this.axios.get(`user/${this.id}`)
      if (this.form.approve == null) {
        this.form = Object.assign(this.form, {approve: approve})
      }
    } else {
      this.form = Object.assign({}, {approve: approve})
    }
  },
  methods: {
    updateimage(imgs) {
      this.form.approve.merchant_poster = imgs
    },
    async onSubmit() {
      const url = this.id ? `user/${this.id}` : `user`
      await this.axios[this.id ? 'put' : 'post'](url, this.form)
      // this.$router.push({name: 'admin.user.normal'});
    }
  }
}
</script>

<style>

</style>
